<?php
namespace app\merchant\controller;

use app\common\controller\Tools;
use app\common\model\LeasingRules as LeasingRulesModel;

class LeasingRules extends Common
{
	
	// 租赁规则模板的添加
	public function create()
	{
		return view('create');
	}
	public function insert()
	{
		$tool = new Tools;
		$data = $_POST;
		return $tool->insert('leasing_rules', $data, 'insert', 'isAjax');
	}


	// 租赁模板列表
	// 数据列表
	public function showlist()
	{
		// 用户列表需要商户的id
		$data = LeasingRulesModel::showlist();
		$pageString = $data->render();
		$this->assign([
			'data' => $data,
			'pageString' => $pageString,
		]);
		return view('showlist');
	}



	public function refresh()
	{
		$data = LeasingRulesModel::refresh();
		if($data)
		{
			return returnJson(1, '刷新成功', $data);
		}else
		{
			return returnJson(1, '刷新失败，请稍后重试！');
		}
	}  
	public function update()
	{
		$id = input('param.id');
		$data = LeasingRulesModel::getLeaseRules($id);
		$this->assign('data', $data);

		// 修改规则模板信息
		if(request()->isPost())
		{
			$data = input('param.');

			$model = new LeasingRulesModel;
			$validate = $model->intValidate();
            if(!($validate->scene('update')->check($data)))
                  return returnJson(0, $validate->getError());


            $result = $model->edit($data['leasing_rules_id'], $data['leasing_rules_name'], $data['leasing_rules_content']);
            // halt(LeasingRulesModel::getLastSql());
			if($result !== false)
			{
				return returnJson(1, '修改成功');
			}else
			{
				return returnJson(0, '修改失败，请稍后重试！');
			}
		}
		return view('update');
	}

	// 删除操作
	public function delete()
	{
		$id = input('id');
		$result = model('leasing_rules')->changeDel($id);
		if(!$result)
			return returnJson(0, '删除失败，请稍后重试');

		return returnJson(1, '删除成功');
	}





}
